package org.jsrml.core.base.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import org.hibernate.annotations.DynamicUpdate;
import org.jsrml.common.persistence.StringIdBaseEntity;
import org.jsrml.common.util.UUIDGenerator;
import org.jsrml.core.base.command.SaveResourceCo;


/**
 * 一个访问地址链接（功能）

 */
@DynamicUpdate
@Entity
@Table(name = M.TABLE_PREFIX + "RESOURCE")
@SuppressWarnings("serial")
public class Resource extends StringIdBaseEntity {

	/**
	 * 上级菜单Id
	 */
	@Column(name = "PARENT_Id",length = 64)
	private String parentId;

	@Column(name = "SORT", length = 4)
	private Integer sort;

	@Column(name = "URL",length = 512)
	private String url;

	@Column(name = "NAME",length = 512)
	private String name;

	@Column(name = "ICON",length = 512)
	private String icon;
	
	@Column(name = "REMARK", length = 512)
	private String remark;

	@Column(name = "PERMISSION", length = 256)
	private String permission;
	
	/**
	 * 菜单归属
	 * 主机方：system1 ，供应方 system2
	 */
	@Column(name = "SYSTEM", length = 64)
	private String system;
	
	public void create(SaveResourceCo command) {
		setId(UUIDGenerator.getUUID());

		setName(command.getName());
		setUrl(command.getUrl());
		setRemark(command.getRemark());
		setSort(command.getSort());
		setParentId(command.getParentId());
		setIcon(command.getIcon());
		
		/**
		 * 先做默认设置
		 */
		setPermission("authc");
		
		setSystem(command.getSystem());
		
	}

	public void modify(SaveResourceCo command) {
		
		setName(command.getName());
		setUrl(command.getUrl());
		setRemark(command.getRemark());
		setSort(command.getSort());
		setParentId(command.getParentId());
		setIcon(command.getIcon());
		setSystem(command.getSystem());
	}

	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getPermission() {
		return permission;
	}

	public void setPermission(String permission) {
		this.permission = permission;
	}

	public String getSystem() {
		return system;
	}

	public void setSystem(String system) {
		this.system = system;
	}

}
